const {
  SimpleTransform,
  PolicyError,
  PolicyInjection
} = require("/root/js-public/wasm-api");
const transform = new SimpleTransform();
transform.subscribe([{{input_topics}}]);
transform.errorHandler(PolicyError.SkipOnFailure);
const filterOdds = (record) => {
  // TODO: Error handling
  const asString = record.value.toString('utf8');
  const asNumber = parseInt(asString, 10);
  return (asNumber % 2) == 0;
}
transform.processRecord((recordBatch) => {
  const result = new Map();
  const transformedBatch = recordBatch.map( ({ header, records }) => {
    return {
      header: recordBatch.header,
      records: records.filter(filterOdds)
    };
  });
  {% for output_topic in output_topics %}
  result.set("{{output_topic}}", transformedBatch);
  {% endfor %}
  return Promise.resolve(result);
});
exports["default"] = transform;
